const Koa=require('koa')
const KoaRouter=require('koa-router')
const indexData=require('./datas/index.json')
const indexCateList=require('./datas/indexCateList.json')
const categoryList=require('./datas/categoryDatas.json')
const goodsList=require('./datas/goods.json')
const app=new Koa()
const router=new　KoaRouter()

app.use(router.routes())

// 首页数据
router.get('/getIndexData',(ctx,next)=>{
	ctx.body=indexData
})

// 首页导航栏切换的数据
router.get('/getIndexCateList',(ctx,next)=>{
	ctx.body=indexCateList
})

//分类数据
router.get('/getCategoryList',(ctx,next)=>{
	ctx.body=categoryList
})

//商品数据
router.get('/getGoodsDetail',(ctx,next)=>{
	const goodsId=ctx.query.goodsId
	ctx.body=goodsList.find(goods=>goods.id===goodsId*1)
})


app.listen(5050,(error)=>{
	if(error){
		console.log(error)
	}else{
		console.log('服务器开启成功')
	}
})
